<?php

namespace app\invoice\controller;

use app\common\base\_Db;
use app\common\controller\CommonController;
use app\common\controller\ResponseJson;
use think\Controller;
use think\Exception;
use think\Request;
use app\common\entity\RequestEntity;
use think\Db;
use think\Session;
use app\invoice\controller\DESDZFP;

class Scan extends Controller{
    public function index(){
        $operater = new RequestEntity('operater', '接口标识', false, 32);
        $orderno = new RequestEntity('orderno', '订单号', false, 32);
        if($operater->text == 'queryInfoByOrderId'){
            $orderinfo = $this->GetOrderInfo($orderno->text);
            $return_data = [];
            $return_data['orderno'] = $orderno->text;
            $return_data['taxtotal'] = $orderinfo['pay_money'];
            $return_data['kptype'] = '1';
            $return_data['fpdm'] = "";
            $return_data['fphm'] = "";
            $return_data['tsfs'] = "0";
            $return_data['qdbz'] = '0';
            $return_data['qdxmmc'] = "";
            $return_data['invoicedate'] = $orderinfo['pay_time'];
            $return_data['message'] = "";
            $return_data['clerk'] = "龙嘉机场";
            $return_data['payee'] = "";
            $return_data['checker'] = "";
            $return_data['deptid'] = "";
            $return_data['clerkid'] = "";
            $return_data['cpybz'] = "";
            $return_data['goodsname']="龙嘉机场大巴车票";
            $return_data['detail'] = [[
                'num'=>'1',
                'hsbz'=>'1',
                'price'=>$orderinfo['pay_money'],
                'taxrate'=>'0.06',
                'spec'=>'',
                'unit'=>'',
                'spbm'=>'3010101020299',//商品编号
                'zsbm'=>'',
                'fphxz'=>'',
                'yhzcbs'=>'',
                'zzstsgl'=>'',
                'lslbs'=>'',
                'taxfreeamt'=>'',//不含税金额
                'tax'=>'',
                'taxamt'=>'',
            ]];
            //hahahaha
            $return_data = json_encode($return_data);
            $DESDZFP = new DESDZFP();
            $return_data = $DESDZFP->encrypt($return_data);
            return $return_data;
        }
    }
    public function GetOrderInfo($orderid){
        $res = Db::name('order_info')
            ->field([
                'pay_time',
                'pay_money',
            ])
            ->where('order_id ='.$orderid)
            ->find();
        return $res;
    }
}